package com.hmall.order;

import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;

@SpringBootTest
public class test {
    @Autowired
    private RabbitTemplate amqpTemplate;

    @Test
    public void send() {
        amqpTemplate.convertAndSend("order.pay.exchange", "order.pay.queue", "大家好我是延迟数据", message -> {
            // 设置延迟毫秒值
            message.getMessageProperties().setExpiration(String.valueOf("10000"));
            return message;
        });
    }

//    /**
//     * 延时队列
//     */
//    @Bean(name = "order.delay.queue")
//    public Queue getMessageQueue() {
//        //dead letter queue
//        return QueueBuilder
//                .durable(RabbitConstant.DEAD_LETTER_QUEUE)
//                // 配置到期后转发的交换
//                .withArgument("x-dead-letter-exchange", "order.close.exchange")
//                // 配置到期后转发的路由键
//                .withArgument("x-dead-letter-routing-key", "order.close.queue")
//                .build();
//    }

    //}
    @Test
    public void senzxcd() {

       // amqpTemplate.convertAndSend("item.topic","item.insert.update","sfsfsdf");
        amqpTemplate.convertAndSend(
                "order.pay.exchange", "order.pay", "大家好我是延迟数据"
                , message -> {
            // 设置延迟毫秒值
            message.getMessageProperties().setExpiration(String.valueOf("9000"));
            return message;
        }
        );
    }

}
